package cn.edu.dutir.corpus.cwt;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Date;

import org.apache.log4j.Logger;
import org.xml.sax.InputSource;

import cn.edu.dutir.corpus.TopicHandler;

import com.aliasi.corpus.InputSourceParser;

public class TWPageParser<H extends TopicHandler> extends InputSourceParser<H> {

	// protected static Logger logger = Logger.getRootLogger();

	private TWPageReader mTWPageReader;

	@Override
	public void parse(InputSource inSrc) throws IOException {
		RandomAccessFile randomFile = new RandomAccessFile(inSrc.getSystemId(),
				"r");
		// logger.warn("Begin parsing file " + inSrc.getSystemId() + " at " +
		// new Date());
		System.out.println("Begin parsing file " + inSrc.getSystemId() + " at "
				+ new Date());
		mTWPageReader = new TWPageReader(randomFile);
		while (mTWPageReader.hasNext()) {
			TWPage page = mTWPageReader.next();
			getHandler().handle(page);
		}
		// logger.info("Finished parsing file " + inSrc.getSystemId() + " at " +
		// new Date());
		System.out.println("Finished parsing file " + inSrc.getSystemId()
				+ " at " + new Date());
	}
}
